package store.lunangangster.nodeflow.core;

import store.lunangangster.nodeflow.common.ResponseCode;

/**
 * 执行结果相应体
 * 
 * @author cwk
 * @version 1.0
 */
public class NodeFlowResponse {
	private boolean success;

	private String message;

	private int code;

	private Throwable cause;

	private NodeFlowResponse() {}

	/**
	 * 通过调用该方法获取一个NodeFlowResponse对象的方法
	 * @return	一个新的NodeFlowResponse对象
	 */
	public static NodeFlowResponse getInstance() {
		return new NodeFlowResponse();
	}

	/**
	 * 设置success状态位
	 * @param success	是否成功
	 * @return	NodeFlowResponse对象
	 */
	public NodeFlowResponse success(boolean success) {
		this.success = success;
		return this;
	}

	/**
	 * 设置message消息体
	 * @param message	消息体
	 * @return	NodeFlowResponse对象
	 */
	public NodeFlowResponse message(String message) {
		this.message = message;
		return this;
	}

	/**
	 * 设置status状态码
	 * @param respCode	状态码封装对象
	 * @return	NodeFlowResponse对象
	 */
	public NodeFlowResponse status(ResponseCode respCode) {
		if (respCode != null) {
			this.code = respCode.code;
			this.message = respCode.message;
		}
		return this;
	}

	/**
	 * 设置code状态码
	 * @param code	状态码
	 * @return	NodeFlowResponse对象
	 */
	public NodeFlowResponse code(int code) {
		this.code = code;
		return this;
	}

	/**
	 * 设置cause异常
	 * @param cause	异常对象
	 * @return	NodeFlowResponse对象
	 */
	public NodeFlowResponse cause(Throwable cause) {
		this.cause = cause;
		return this;
	}

	/**
	 * 是否成功
	 * @return	如果成功返回true
	 */
	public boolean isSuccess() {
		return success;
	}

	/**
	 * 获取消息体
	 * @return	消息体
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * 获取状态码
	 * @return	状态码
	 */
	public int getCode() {
		return code;
	}

	/**
	 * 获取异常对象
	 * @return	异常对象
	 */
	public Throwable getCause() {
		return cause;
	}

	@Override
	public String toString() {
		return "NodeFlowResponse{" +
				"success=" + success +
				", message='" + message + '\'' +
				", code=" + code +
				", cause=" + cause +
				'}';
	}
}
